<template>
	<view class="home">
		<view class="padding-30 bg-ff radius-10 margin-bottom-20" v-for="(item,index) in list" :key="index" @click="selectAddress(item)">
			<view class="flex align-center">
				<view class="text-28">{{item.consignee}}</view>
				<view class="text-28 text-b5 margin-left-10">{{item.mobile}}</view>
				<view class="bg-main text-ff morenbtn" v-if="item.is_default==1">默认</view>
				<view class="flex-one"></view>
				<view class="text-1a" @click.stop="go('/subpages/set/addressedit?id='+item.id)">
					<u-icon name="edit-pen" size="20"></u-icon>
				</view>
				<view class="text-30 text-1a margin-left-20" @click.stop="getDel(item.id)">
					<u-icon name="trash" size="20"></u-icon>
				</view>
			</view>
			<view class="text-26 margin-top-30">{{item.province_name}}{{item.city_name}}{{item.district_name}}{{item.address}}</view>
		</view>
		<view class="noadress" v-if="list&&list.length==0">
			<image src="/static/noadress.png" mode="" class="noimg"></image>
			<view class="text-28 text-c5 margin-top-15">您还没有添加地址哦!</view>
		</view>
		<view class="btn width-100p padding-lr-30" @click="go('/subpages/set/addressedit')">
			<view class="line-height-80 radius-40 bg-main text-center text-28 text-ff">新增地址</view>
		</view>
		<u-popup :show="showTip" mode="center" @close="showTip=false" @open="showTip=true" closeable="true"
			round="10">
			<view class="pop-bg">
				提示
				<view class="text">
					确认删除此地址？
				</view>
				<view class="pop_btn">
					<view class="confirm" @click="showTip=false">我再想想</view>
					<view class="cancel" @click="confirmTip">确认删除</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				list:[],
				showTip:false,
				currentId:null
			}
		},
		onShow() {
			this.getlist()
		},
		methods: {
			getlist(){
				this.rq.getData('address/list').then(res => {
					if (res.code == 1) {
						this.list = res.data
					}
				})
			},
			selectAddress(item){
				setTimeout(()=>{
					uni.$emit('address',item)					
				},500)		
				uni.navigateBack()
			},
			go(url){
				uni.navigateTo({
					url:url
				})
			},
			getDel(id) {
				this.showTip = true
				this.currentId = id
			},
			confirmTip(){
				this.rq.getData('address/delete',{id:this.currentId}).then(res=>{
					this.showTip = false
					uni.showToast({
						title:'删除成功~',
						icon:'none'
					})
					this.getlist()
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.home {
		width: 100%;
		min-height: 100vh;
		background: #f6f6f6;
		padding-top: 30rpx;
		padding-left: 30rpx;
		padding-right: 30rpx;
		box-sizing: border-box;
		padding-bottom: calc(env(safe-area-inset-bottom) + 140rpx);
	}

	.text-b5 {
		color: #B5B5B5;
	}

	.btn {
		position: fixed;
		left: 0;
		bottom: calc(30rpx + env(safe-area-inset-bottom));
	}
	.noadress{
		padding-top: 350rpx;
		display: flex;
		align-items: center;
		flex-direction: column;
	}
	.noimg{
		width: 400rpx;
		height: 344rpx;
	}
	.text-c5{
		color: #C5C5C5;
	}
	.morenbtn{
		width: 85rpx;
		height: 37rpx;
		font-size: 24rpx;
		border-radius: 13rpx;
		line-height: 37rpx;
		text-align: center;
		margin-left: 30rpx;
	}
	.padding-30{
		padding: 30rpx;
	}
	.width-100p{
		width: 100%;
		box-sizing: border-box;
	}
	.line-height-80{
		line-height: 80rpx;
	}
	.bg-ff{
		background: #fff;
	}
	.radius-10{
		border-radius: 10rpx;
	}
	.radius-40{
		border-radius: 40rpx;
	}
	.margin-top-30{
		margin-top: 30rpx;
	}
	.margin-bottom-15{
		margin-top: 15rpx;
	}
	.margin-bottom-20{
		margin-bottom: 20rpx;
	}
	.flex{
		display: flex;
	}
	.flex-one{
		flex: 1;
	}
	.bg-main{
		background: #FF5866;
	}
	.align-center{
		align-items: center;
	}
	.text-26{
		font-size: 28rpx;
	}
	.text-28{
		font-size: 28rpx;
	}
	.text-30{
		font-size: 30rpx;
	}
	
	.text-b5{
		color: #b5b5b5;
	}
	.text-1a{
		color: #1a1a1a;
	}
	.text-ff{
		color: #ffffff;
	}
	.margin-left-10{
		margin-left: 10rpx;
	}
	.margin-left-20{
		margin-left: 20rpx;
	}
	.text-center{
		text-align: center;
	}
	.padding-lr-30{
		padding-left: 30rpx;
		padding-right: 30rpx;
	}
	.pop-bg {
		width: 606rpx;
		height: 403rpx;
		border-radius: 8px;
		opacity: 1;
		background: #FFFFFF;
		font-family: PingFang SC;
		font-size: 16px;
		font-weight: normal;
		line-height: 14px;
		letter-spacing: 0px;
		color: #333333;
		padding: 40rpx;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		text-align: center;
		
		.text {
			margin: 50rpx 0 0;
		}
	
		.pop_btn {
			display: flex;
			align-items: center;
			justify-content: space-around;
			margin-top: auto;
			width: 100%;
	
			.cancel {
				width: 98px;
				height: 34px;
				border-radius: 102px;
				opacity: 1;
	
				background: #F7F7F7;
	
				border: 1px solid #F7F7F7;
				color: #333333;
				display: flex;
				align-items: center;
				justify-content: center;
			}
	
			.confirm {
				width: 98px;
				height: 34px;
				border-radius: 102px;
				opacity: 1;
	
				background: #FF5866;
	
				border: 1px solid #FF5866;
				color: #ffffff;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
	}
</style>